package test;

import java.io.File;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;

import com.kzw.dao.ArticleDao;
import com.kzw.entity.Article;

import my.json.Jackson;

public class T1 {

	public static void main(String[] args) throws Exception {
		
		ArticleDao dao = new ArticleDao();

		String path = T1.class.getResource("/newsList.json").toURI().getPath();
		File file = new File(path);
		String json = FileUtils.readFileToString(file, "UTF-8");
		
		Map<String, Object> map = Jackson.me().fromJson(json, Map.class);
		List<Map<String, Object>> list =  (List<Map<String, Object>>)map.get("data");
		for(Map<String, Object> art : list) {
			Article a = new Article();
			a.setAuthor(art.get("newsAuthor")+"");
			a.setContent(art.get("content")+"");
			a.setImgPath(art.get("newsImg")+"");
			a.setTitle(art.get("newsName")+"");
			a.setInfo(art.get("abstract")+"");
			a.setStatus(1);
			a.setOpen(1);
			a.setTop(0);
			
			dao.save(a);
		}
	}
}
